package designPattern.singleton.lazy.thread;

public class ThreadSingleton {
    //volatile关键字解决指令重排序问题
    private volatile static ThreadSingleton INSTANCE;

    private ThreadSingleton() {

    }
    //解决多线程问题，但存在指令重排序问题
    public static ThreadSingleton getInstance() {
        if (INSTANCE == null) {
            synchronized (ThreadSingleton.class) {
                if(INSTANCE == null) {
                    INSTANCE = new ThreadSingleton();
                }
            }
        }
        return INSTANCE;
    }
}
